Node-RED block in Snap4City Microservice library node-red-contrib-snap4city-developer is "save-typical-time-trends">
It allows to save typical time trend's data in the API. The services can be used in many different ways:
1) You can save a complete JSON that come from a plumber-data-analytic or from a function node through msg.payload;
2) You can save the value and error part of the JSON that come from a function node and insert manually the other parameters by compiling the form that is present in the save-typical-time-trends node. Pay attention because the complete JSON with parameters, values and errors, takes precedence over the parameters entered by the user. So if you insert a complete JSON in msg.payload the node will ignore the parameters inserted manually from the UI.
Inputs
The input comes from msg.payload.response if you use the Typical Time Trend script or come from msg.payload and the manual parameters if you don't use the R script.
- serviceUri
string
- This is the uri of the sensor used as source of raw data. An examlpe is "http://www.disit.org/km4city/resource/METRO11/averageSpeed". You can find other type of sensor in the "Data Inspector" of Snap4city.
- deviceName
string
- This is the name of the device that owns sensors. This name must be the same that is present in the Service Uri field. If the service uri is "http://www.disit.org/km4city/resource/METRO11/averageSpeed" the Device Name must be "METRO11".
- valueName
string
- This is the name of the sensor that is also the name of the calculated value. This name must be the same that is present in the Service Uri field. If the service uri is "http://www.disit.org/km4city/resource/METRO11/averageSpeed" the Value Name must be "averageSpeed".
- valueUnit
string
- This is the name of the metric unit related with the Value Name. An example can be "km/h" for "averageSpeed"
- referenceDate
string
- The format must be this: "yyyy-mm-dd". This is the data chosen to select the period used to collect raw data from sensors.
- numberOfPeriods
number
- This is the number of how many months or week that are used to compute the trends.
- from
string
- The format must be this: "yyyy-mm-dd". With reference date and number of periods we define the time interval of computations. This is the start data of the interval.
- to
string
- The format must be this: "yyyy-mm-dd". With reference date and number of periods we define the time interval of computations. This is the end data of the interval.
- trendType
string
- This is the trend type that you want to save. There are 3 typical trend: monthDay, monthWeek and dayHour.
- computationType
string
- This is the computation type that you want to use. There are 4 computation type: average, median, min or max.
- JSON Input
- After completing the compilation of the previous form it is necessary to insert in input a JSON by linking this block with a function block that produces a JSON that contain the values that will be saved. These values have different formatting based on the selected trend. Below you can see how the three JSON must be constituted:
- typicalMonthWeek
- This must be an array with 28 numerical values in string format. The array must be named with "typicalMonthWeek". So let's see an example of this JSON:
"typicalMonthWeek": [
"46.2096",
"51.4195",
"48.7888",
...
]
- typicalMonthD
- This must be an array with 30 numerical values in string format. The array must be named with "typicalMonthD". So let's see an example of this JSON:
"typicalMonthD": [
"46.2096",
"51.4195",
"48.7888",
...
]
- typicalDays
- This must be a JSON consisting of 7 array. Each one of this array must contain 24 numerical values in string format.The main array must be named with "typicalDays". The other seven array must be named with the day of the week like "Monday" and so on.So let's see an example of this JSON:
"typicalDays": {
"Monday": [
"46.2096",
"51.4195",
"48.7888",
.....
],
"Tuesday": [
"46.2096",
"51.4195",
"48.7888",
.....
],
.......
"Sunday": [......]
}
- wrongValues
This is an array which contains an array of string where you can report the error about raw data, like missing values or negative values. Based on the trend we choose, we will have arrays with a different structure.
- monthWeekError
This is a simple array of string, like the example below:
"wrongValues": {
"monthWeekError":[
"In this period: 2020-09-30T12:00:00 - 2020-09-30T13:00:00 there aren't value"
]
}
- monthDayError
This is a simple array of string, like the example below:
"wrongValues": {
"monthDayError":"No error for this trend"
}
- dayHourError
For this trend we have 7 arrays, one for each day of the week (mondayError,tuesdayError,wednesdayError,thursdayError,fridayError,saturdayError,sundayError). For more details see the example below:
"wrongValues": {
"mondayError": "No error for this trend",
"tuesdayError": "No error for this trend",
"wednesdayError": [
"In this period: 2020-09-30T12:00:00 - 2020-09-30T13:00:00 there aren't value"
],
"thursdayError": [
"In this period: 2020-10-01T00:00:00 - 2020-10-01T01:00:00 there aren't value"
],
"fridayError": "No error for this trend",
"saturdayError": "No error for this trend",
"sundayError": "No error for this trend"
}
Complete Input Example
This is an example of a complete JSON input for the monthDay trend:
{
"serviceUri": "http://www.disit.org/km4city/resource/METRO11",
"deviceName": "METRO11",
"valueName": "averageSpeed",
"valueUnit": "km/h",
"referenceDate": "2020-10-12",
"numberOfPeriods": 2,
"from": "2020-08-01",
"to": "2020-09-30",
"trendType": "monthDay",
"computationType": "average",
"typicalMonthD": [
"59.2039",
"58.8606",
"59.1556",
"59.2643",
"59.2175",
"58.7546",
"59.0367",
"58.89",
"59.0059",
"59.6978",
"59.8696",
"59.5698",
"57.9666",
"59.5293",
"59.3678",
"58.8308",
"59.8795",
"59.6743",
"59.4784",
"59.1038",
"58.9039",
"58.9305",
"58.7942",
"60.0248",
"59.9674",
"59.9843",
"59.8559",
"59.6011",
"59.486",
"59.4171"
],
"wrongValues": {
"monthDayError": "No error for this trend"
}
}
Outputs
The output is the result of the operations: "Success" or the error code.
Details
The node can receive a JSON with the parameters described in the Inputs section and with them generate the output JSON. If the values are not present in the input JSON, these are read by those in the configuration. If they are not present in either part, an error is generated for the necessary parameters.